package org.jeecg.common.json;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.serializer.ValueFilter;

import java.util.Date;

/**
 * 日期json序列化器
 *
 * @author zhanglei01
 * @date 2022/03/09
 */
public class DateJsonSerializer implements ValueFilter {

    private static final DateJsonSerializer instance = new DateJsonSerializer();

    private DateJsonSerializer() {
    }

    public static DateJsonSerializer getInstance() {
        return instance;
    }
    @Override
    public Object process(Object object, String name, Object value) {
        if (ObjectUtil.isEmpty(value)) {
            return value;
        }
        if (value.getClass().equals(Date.class)) {
            value = DateUtil.formatDateTime((Date) value);
        }
        return value;
    }
}
